{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3f2cdc29",
   "metadata": {},
   "source": [
    "# 折线 时序 柱状"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "4258476c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using data directory: C:\\Users\\MateBook 13\\.bokeh\\data\n",
      "Skipping 'CGM.csv' (checksum match)\n",
      "Skipping 'US_Counties.zip' (checksum match)\n",
      "Skipping 'us_cities.json' (checksum match)\n",
      "Skipping 'unemployment09.csv' (checksum match)\n",
      "Skipping 'AAPL.csv' (checksum match)\n",
      "Skipping 'FB.csv' (checksum match)\n",
      "Skipping 'GOOG.csv' (checksum match)\n",
      "Skipping 'IBM.csv' (checksum match)\n",
      "Skipping 'MSFT.csv' (checksum match)\n",
      "Skipping 'WPP2012_SA_DB03_POPULATION_QUINQUENNIAL.zip' (checksum match)\n",
      "Skipping 'gapminder_fertility.csv' (checksum match)\n",
      "Skipping 'gapminder_population.csv' (checksum match)\n",
      "Skipping 'gapminder_life_expectancy.csv' (checksum match)\n",
      "Skipping 'gapminder_regions.csv' (checksum match)\n",
      "Skipping 'world_cities.zip' (checksum match)\n",
      "Skipping 'airports.json' (checksum match)\n",
      "Skipping 'movies.db.zip' (checksum match)\n",
      "Skipping 'airports.csv' (checksum match)\n",
      "Skipping 'routes.csv' (checksum match)\n",
      "Skipping 'haarcascade_frontalface_default.xml' (checksum match)\n"
     ]
    }
   ],
   "source": [
    "import bokeh\n",
    "bokeh.sampledata.download()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "f01e0d97",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"1910\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(root) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  const force = true;\n",
       "\n",
       "  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n",
       "    root._bokeh_onload_callbacks = [];\n",
       "    root._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "  const JS_MIME_TYPE = 'application/javascript';\n",
       "  const HTML_MIME_TYPE = 'text/html';\n",
       "  const EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
       "  const CLASS_NAME = 'output_bokeh rendered_html';\n",
       "\n",
       "  /**\n",
       "   * Render data to the DOM node\n",
       "   */\n",
       "  function render(props, node) {\n",
       "    const script = document.createElement(\"script\");\n",
       "    node.appendChild(script);\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when an output is cleared or removed\n",
       "   */\n",
       "  function handleClearOutput(event, handle) {\n",
       "    const cell = handle.cell;\n",
       "\n",
       "    const id = cell.output_area._bokeh_element_id;\n",
       "    const server_id = cell.output_area._bokeh_server_id;\n",
       "    // Clean up Bokeh references\n",
       "    if (id != null && id in Bokeh.index) {\n",
       "      Bokeh.index[id].model.document.clear();\n",
       "      delete Bokeh.index[id];\n",
       "    }\n",
       "\n",
       "    if (server_id !== undefined) {\n",
       "      // Clean up Bokeh references\n",
       "      const cmd_clean = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
       "      cell.notebook.kernel.execute(cmd_clean, {\n",
       "        iopub: {\n",
       "          output: function(msg) {\n",
       "            const id = msg.content.text.trim();\n",
       "            if (id in Bokeh.index) {\n",
       "              Bokeh.index[id].model.document.clear();\n",
       "              delete Bokeh.index[id];\n",
       "            }\n",
       "          }\n",
       "        }\n",
       "      });\n",
       "      // Destroy server and session\n",
       "      const cmd_destroy = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
       "      cell.notebook.kernel.execute(cmd_destroy);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when a new output is added\n",
       "   */\n",
       "  function handleAddOutput(event, handle) {\n",
       "    const output_area = handle.output_area;\n",
       "    const output = handle.output;\n",
       "\n",
       "    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
       "    if ((output.output_type != \"display_data\") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {\n",
       "      return\n",
       "    }\n",
       "\n",
       "    const toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
       "\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
       "      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
       "      // store reference to embed id on output_area\n",
       "      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
       "    }\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
       "      const bk_div = document.createElement(\"div\");\n",
       "      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
       "      const script_attrs = bk_div.children[0].attributes;\n",
       "      for (let i = 0; i < script_attrs.length; i++) {\n",
       "        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
       "        toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n",
       "      }\n",
       "      // store reference to server id on output_area\n",
       "      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function register_renderer(events, OutputArea) {\n",
       "\n",
       "    function append_mime(data, metadata, element) {\n",
       "      // create a DOM node to render to\n",
       "      const toinsert = this.create_output_subarea(\n",
       "        metadata,\n",
       "        CLASS_NAME,\n",
       "        EXEC_MIME_TYPE\n",
       "      );\n",
       "      this.keyboard_manager.register_events(toinsert);\n",
       "      // Render to node\n",
       "      const props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
       "      render(props, toinsert[toinsert.length - 1]);\n",
       "      element.append(toinsert);\n",
       "      return toinsert\n",
       "    }\n",
       "\n",
       "    /* Handle when an output is cleared or removed */\n",
       "    events.on('clear_output.CodeCell', handleClearOutput);\n",
       "    events.on('delete.Cell', handleClearOutput);\n",
       "\n",
       "    /* Handle when a new output is added */\n",
       "    events.on('output_added.OutputArea', handleAddOutput);\n",
       "\n",
       "    /**\n",
       "     * Register the mime type and append_mime function with output_area\n",
       "     */\n",
       "    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
       "      /* Is output safe? */\n",
       "      safe: true,\n",
       "      /* Index of renderer in `output_area.display_order` */\n",
       "      index: 0\n",
       "    });\n",
       "  }\n",
       "\n",
       "  // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
       "  if (root.Jupyter !== undefined) {\n",
       "    const events = require('base/js/events');\n",
       "    const OutputArea = require('notebook/js/outputarea').OutputArea;\n",
       "\n",
       "    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
       "      register_renderer(events, OutputArea);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  \n",
       "  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    root._bokeh_timeout = Date.now() + 5000;\n",
       "    root._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  const NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    const el = document.getElementById(\"1910\");\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\n",
       "    } else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "\n",
       "  function run_callbacks() {\n",
       "    try {\n",
       "      root._bokeh_onload_callbacks.forEach(function(callback) {\n",
       "        if (callback != null)\n",
       "          callback();\n",
       "      });\n",
       "    } finally {\n",
       "      delete root._bokeh_onload_callbacks\n",
       "    }\n",
       "    console.debug(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(css_urls, js_urls, callback) {\n",
       "    if (css_urls == null) css_urls = [];\n",
       "    if (js_urls == null) js_urls = [];\n",
       "\n",
       "    root._bokeh_onload_callbacks.push(callback);\n",
       "    if (root._bokeh_is_loading > 0) {\n",
       "      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    root._bokeh_is_loading = css_urls.length + js_urls.length;\n",
       "\n",
       "    function on_load() {\n",
       "      root._bokeh_is_loading--;\n",
       "      if (root._bokeh_is_loading === 0) {\n",
       "        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
       "        run_callbacks()\n",
       "      }\n",
       "    }\n",
       "\n",
       "    function on_error(url) {\n",
       "      console.error(\"failed to load \" + url);\n",
       "    }\n",
       "\n",
       "    for (let i = 0; i < css_urls.length; i++) {\n",
       "      const url = css_urls[i];\n",
       "      const element = document.createElement(\"link\");\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error.bind(null, url);\n",
       "      element.rel = \"stylesheet\";\n",
       "      element.type = \"text/css\";\n",
       "      element.href = url;\n",
       "      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
       "      document.body.appendChild(element);\n",
       "    }\n",
       "\n",
       "    for (let i = 0; i < js_urls.length; i++) {\n",
       "      const url = js_urls[i];\n",
       "      const element = document.createElement('script');\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error.bind(null, url);\n",
       "      element.async = false;\n",
       "      element.src = url;\n",
       "      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.head.appendChild(element);\n",
       "    }\n",
       "  };\n",
       "\n",
       "  function inject_raw_css(css) {\n",
       "    const element = document.createElement(\"style\");\n",
       "    element.appendChild(document.createTextNode(css));\n",
       "    document.body.appendChild(element);\n",
       "  }\n",
       "\n",
       "  \n",
       "  const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.1.min.js\"];\n",
       "  const css_urls = [];\n",
       "  \n",
       "\n",
       "  const inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    function(Bokeh) {\n",
       "    \n",
       "    \n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if (root.Bokeh !== undefined || force === true) {\n",
       "      \n",
       "    for (let i = 0; i < inline_js.length; i++) {\n",
       "      inline_js[i].call(root, root.Bokeh);\n",
       "    }\n",
       "    if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!root._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      root._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      const cell = $(document.getElementById(\"1910\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (root._bokeh_is_loading === 0) {\n",
       "    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(css_urls, js_urls, function() {\n",
       "      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  const force = true;\n\n  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\n  \n\n  \n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  const NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded() {\n    const el = document.getElementById(\"1910\");\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(display_loaded, 100)\n    }\n  }\n\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) {\n        if (callback != null)\n          callback();\n      });\n    } finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.debug(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(css_urls, js_urls, callback) {\n    if (css_urls == null) css_urls = [];\n    if (js_urls == null) js_urls = [];\n\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n    function on_load() {\n      root._bokeh_is_loading--;\n      if (root._bokeh_is_loading === 0) {\n        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n        run_callbacks()\n      }\n    }\n\n    function on_error(url) {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (let i = 0; i < css_urls.length; i++) {\n      const url = css_urls[i];\n      const element = document.createElement(\"link\");\n      element.onload = on_load;\n      element.onerror = on_error.bind(null, url);\n      element.rel = \"stylesheet\";\n      element.type = \"text/css\";\n      element.href = url;\n      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n      document.body.appendChild(element);\n    }\n\n    for (let i = 0; i < js_urls.length; i++) {\n      const url = js_urls[i];\n      const element = document.createElement('script');\n      element.onload = on_load;\n      element.onerror = on_error.bind(null, url);\n      element.async = false;\n      element.src = url;\n      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.head.appendChild(element);\n    }\n  };\n\n  function inject_raw_css(css) {\n    const element = document.createElement(\"style\");\n    element.appendChild(document.createTextNode(css));\n    document.body.appendChild(element);\n  }\n\n  \n  const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.1.min.js\"];\n  const css_urls = [];\n  \n\n  const inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    function(Bokeh) {\n    \n    \n    }\n  ];\n\n  function run_inline_js() {\n    \n    if (root.Bokeh !== undefined || force === true) {\n      \n    for (let i = 0; i < inline_js.length; i++) {\n      inline_js[i].call(root, root.Bokeh);\n    }\n    if (force === true) {\n        display_loaded();\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      const cell = $(document.getElementById(\"1910\")).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(css_urls, js_urls, function() {\n      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.plotting import figure,output_notebook,show\n",
    "output_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd418fe7",
   "metadata": {},
   "source": [
    "## 折线图"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9f577ef5",
   "metadata": {},
   "source": [
    "### 折线图(单线条) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "35a37f51",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"aa996d3d-0abe-44c6-a002-fcb649b868bb\" data-root-id=\"1911\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"fd221739-bada-4e88-8671-423016e8b7ad\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1922\"}],\"center\":[{\"id\":\"1925\"},{\"id\":\"1929\"},{\"id\":\"1960\"}],\"height\":300,\"left\":[{\"id\":\"1926\"}],\"renderers\":[{\"id\":\"1948\"}],\"title\":{\"id\":\"1912\"},\"toolbar\":{\"id\":\"1937\"},\"width\":300,\"x_range\":{\"id\":\"1914\"},\"x_scale\":{\"id\":\"1918\"},\"y_range\":{\"id\":\"1916\"},\"y_scale\":{\"id\":\"1920\"}},\"id\":\"1911\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1952\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1934\",\"type\":\"ResetTool\"},{\"attributes\":{\"label\":{\"value\":\"Temp.\"},\"renderers\":[{\"id\":\"1948\"}]},\"id\":\"1961\",\"type\":\"LegendItem\"},{\"attributes\":{\"line_color\":\"#1f77b4\",\"line_width\":2,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1945\",\"type\":\"Line\"},{\"attributes\":{\"tools\":[{\"id\":\"1930\"},{\"id\":\"1931\"},{\"id\":\"1932\"},{\"id\":\"1933\"},{\"id\":\"1934\"},{\"id\":\"1935\"}]},\"id\":\"1937\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1953\",\"type\":\"AllLabels\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"1936\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1955\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"overlay\":{\"id\":\"1936\"}},\"id\":\"1932\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1923\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1922\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"1925\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1918\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1931\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1933\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1957\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"line_width\":2,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1946\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"1935\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1958\",\"type\":\"Selection\"},{\"attributes\":{\"line_alpha\":0.2,\"line_color\":\"#1f77b4\",\"line_width\":2,\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"1947\",\"type\":\"Line\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"items\":[{\"id\":\"1961\"}]},\"id\":\"1960\",\"type\":\"Legend\"},{\"attributes\":{},\"id\":\"1956\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"1916\",\"type\":\"DataRange1d\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"line example\"},\"id\":\"1912\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1920\",\"type\":\"LinearScale\"},{\"attributes\":{\"axis_label\":\"x\",\"coordinates\":null,\"formatter\":{\"id\":\"1955\"},\"group\":null,\"major_label_policy\":{\"id\":\"1956\"},\"ticker\":{\"id\":\"1923\"}},\"id\":\"1922\",\"type\":\"LinearAxis\"},{\"attributes\":{\"source\":{\"id\":\"1944\"}},\"id\":\"1949\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1914\",\"type\":\"DataRange1d\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1944\"},\"glyph\":{\"id\":\"1945\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"1947\"},\"nonselection_glyph\":{\"id\":\"1946\"},\"view\":{\"id\":\"1949\"}},\"id\":\"1948\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1930\",\"type\":\"PanTool\"},{\"attributes\":{\"data\":{\"x\":[1,2,3,4,5,6,7],\"y\":[6,7,2,4,5,10,4]},\"selected\":{\"id\":\"1958\"},\"selection_policy\":{\"id\":\"1957\"}},\"id\":\"1944\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1927\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis_label\":\"y\",\"coordinates\":null,\"formatter\":{\"id\":\"1952\"},\"group\":null,\"major_label_policy\":{\"id\":\"1953\"},\"ticker\":{\"id\":\"1927\"}},\"id\":\"1926\",\"type\":\"LinearAxis\"},{\"attributes\":{\"axis\":{\"id\":\"1926\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1929\",\"type\":\"Grid\"}],\"root_ids\":[\"1911\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.1\"}};\n",
       "  const render_items = [{\"docid\":\"fd221739-bada-4e88-8671-423016e8b7ad\",\"root_ids\":[\"1911\"],\"roots\":{\"1911\":\"aa996d3d-0abe-44c6-a002-fcb649b868bb\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1911"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 数据\n",
    "x = [1, 2, 3, 4, 5, 6, 7]\n",
    "y = [6, 7, 2, 4, 5, 10, 4]\n",
    "\n",
    "# 画布：坐标轴标签，画布大小\n",
    "p = figure(\n",
    "    title=\"line example\", \n",
    "    x_axis_label='x', \n",
    "    y_axis_label='y', \n",
    "    width=300, \n",
    "    height=300\n",
    ")\n",
    "# 在画布绘制图形\n",
    "p.line(x, y, legend=\"Temp.\", line_width=2)  # 折线 （legend 图例）\n",
    "\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d8bbf6c0",
   "metadata": {},
   "source": [
    "### 折线图(多线条)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "6b18b61b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"44ba4758-2620-44a9-a4a6-a3026cc54098\" data-root-id=\"2082\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"00d1e1e1-1369-471c-8ede-0d34a2d677df\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2093\"}],\"center\":[{\"id\":\"2096\"},{\"id\":\"2100\"}],\"height\":300,\"left\":[{\"id\":\"2097\"}],\"renderers\":[{\"id\":\"2119\"}],\"title\":{\"id\":\"2083\"},\"toolbar\":{\"id\":\"2108\"},\"width\":300,\"x_range\":{\"id\":\"2085\"},\"x_scale\":{\"id\":\"2089\"},\"y_range\":{\"id\":\"2087\"},\"y_scale\":{\"id\":\"2091\"}},\"id\":\"2082\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"2105\",\"type\":\"ResetTool\"},{\"attributes\":{\"data\":{\"line_alpha\":[0.4,0.8],\"line_color\":[\"firbrick\",\"navy\"],\"xs\":[[2,4,6,7],[3,5,7,8,9,12]],\"ys\":[[3,4,2,1],[2,4,5,6,7,5]]},\"selected\":{\"id\":\"2199\"},\"selection_policy\":{\"id\":\"2198\"}},\"id\":\"2115\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"2197\",\"type\":\"AllLabels\"},{\"attributes\":{\"axis\":{\"id\":\"2097\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"2100\",\"type\":\"Grid\"},{\"attributes\":{\"source\":{\"id\":\"2115\"}},\"id\":\"2120\",\"type\":\"CDSView\"},{\"attributes\":{\"line_alpha\":{\"value\":0.2},\"line_color\":{\"field\":\"line_color\"},\"xs\":{\"field\":\"xs\"},\"ys\":{\"field\":\"ys\"}},\"id\":\"2118\",\"type\":\"MultiLine\"},{\"attributes\":{},\"id\":\"2091\",\"type\":\"LinearScale\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"2107\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"2198\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"2094\",\"type\":\"BasicTicker\"},{\"attributes\":{\"line_alpha\":{\"field\":\"line_alpha\"},\"line_color\":{\"field\":\"line_color\"},\"xs\":{\"field\":\"xs\"},\"ys\":{\"field\":\"ys\"}},\"id\":\"2116\",\"type\":\"MultiLine\"},{\"attributes\":{},\"id\":\"2199\",\"type\":\"Selection\"},{\"attributes\":{\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"line_color\"},\"xs\":{\"field\":\"xs\"},\"ys\":{\"field\":\"ys\"}},\"id\":\"2117\",\"type\":\"MultiLine\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2196\"},\"group\":null,\"major_label_policy\":{\"id\":\"2197\"},\"ticker\":{\"id\":\"2094\"}},\"id\":\"2093\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"2089\",\"type\":\"LinearScale\"},{\"attributes\":{\"tools\":[{\"id\":\"2101\"},{\"id\":\"2102\"},{\"id\":\"2103\"},{\"id\":\"2104\"},{\"id\":\"2105\"},{\"id\":\"2106\"}]},\"id\":\"2108\",\"type\":\"Toolbar\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"multi_line\"},\"id\":\"2083\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"2106\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"2098\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"2093\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"2096\",\"type\":\"Grid\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2193\"},\"group\":null,\"major_label_policy\":{\"id\":\"2194\"},\"ticker\":{\"id\":\"2098\"}},\"id\":\"2097\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"2193\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"2101\",\"type\":\"PanTool\"},{\"attributes\":{\"overlay\":{\"id\":\"2107\"}},\"id\":\"2103\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"2115\"},\"glyph\":{\"id\":\"2116\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"2118\"},\"nonselection_glyph\":{\"id\":\"2117\"},\"view\":{\"id\":\"2120\"}},\"id\":\"2119\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"2194\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"2085\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"2104\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"2196\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"2102\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"2087\",\"type\":\"DataRange1d\"}],\"root_ids\":[\"2082\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.1\"}};\n",
       "  const render_items = [{\"docid\":\"00d1e1e1-1369-471c-8ede-0d34a2d677df\",\"root_ids\":[\"2082\"],\"roots\":{\"2082\":\"44ba4758-2620-44a9-a4a6-a3026cc54098\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2082"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 数据\n",
    "x = [[2,4,6,7],[3,5,7,8,9,12]]\n",
    "y = [[3,4,2,1],[2,4,5,6,7,5]]\n",
    "\n",
    "# 画布\n",
    "p = figure(title=\"multi_line\",plot_width=300,plot_height=300)\n",
    "p.multi_line(x,y,color=['firbrick','navy'],alpha=[0.4,0.8])\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d8cee016",
   "metadata": {},
   "source": [
    "## 折线图实践"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f6a9814c",
   "metadata": {},
   "source": [
    "### 示例代码（数学模型）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "ff361ac7",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n",
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"fcc313e6-62fa-49a4-a33f-e579d490349d\" data-root-id=\"2251\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"9ce83511-c002-43a7-8bd5-e20a7a5a094e\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2262\"}],\"center\":[{\"id\":\"2265\"},{\"id\":\"2269\"},{\"id\":\"2296\"}],\"height\":300,\"left\":[{\"id\":\"2266\"}],\"renderers\":[{\"id\":\"2284\"},{\"id\":\"2302\"},{\"id\":\"2320\"},{\"id\":\"2341\"},{\"id\":\"2364\"},{\"id\":\"2388\"}],\"title\":{\"id\":\"2252\"},\"toolbar\":{\"id\":\"2275\"},\"width\":300,\"x_range\":{\"id\":\"2254\"},\"x_scale\":{\"id\":\"2258\"},\"y_range\":{\"id\":\"2256\"},\"y_scale\":{\"id\":\"2260\"}},\"id\":\"2251\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"2258\",\"type\":\"LinearScale\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"white\"},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"size\":{\"value\":8},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2300\",\"type\":\"Circle\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"white\"},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"red\"},\"size\":{\"value\":6},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2363\",\"type\":\"Circle\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.2},\"fill_color\":{\"value\":\"white\"},\"hatch_alpha\":{\"value\":0.2},\"line_alpha\":{\"value\":0.2},\"line_color\":{\"value\":\"#1f77b4\"},\"size\":{\"value\":8},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2301\",\"type\":\"Circle\"},{\"attributes\":{\"data\":{\"x\":[0.1,0.5,1.0,1.5,2.0,2.5,3.0],\"y\":[1.2589254117941673,3.1622776601683795,10.0,31.622776601683793,100.0,316.22776601683796,1000.0]},\"selected\":{\"id\":\"2382\"},\"selection_policy\":{\"id\":\"2381\"}},\"id\":\"2360\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"white\"},\"hatch_alpha\":{\"value\":0.1},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"red\"},\"size\":{\"value\":6},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2362\",\"type\":\"Circle\"},{\"attributes\":{\"overlay\":{\"id\":\"2274\"}},\"id\":\"2271\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"line_alpha\":0.2,\"line_color\":\"#FFB6C1\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2319\",\"type\":\"Line\"},{\"attributes\":{\"source\":{\"id\":\"2360\"}},\"id\":\"2365\",\"type\":\"CDSView\"},{\"attributes\":{\"line_color\":\"red\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2338\",\"type\":\"Line\"},{\"attributes\":{\"data\":{\"x\":[0.1,0.5,1.0,1.5,2.0,2.5,3.0],\"y\":[1.2589254117941673,3.1622776601683795,10.0,31.622776601683793,100.0,316.22776601683796,1000.0]},\"selected\":{\"id\":\"2357\"},\"selection_policy\":{\"id\":\"2356\"}},\"id\":\"2337\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"label\":{\"value\":\"y=10^x\"},\"renderers\":[{\"id\":\"2341\"},{\"id\":\"2364\"}]},\"id\":\"2359\",\"type\":\"LegendItem\"},{\"attributes\":{\"num_minor_ticks\":10},\"id\":\"2267\",\"type\":\"LogTicker\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"2316\"},\"glyph\":{\"id\":\"2317\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"2319\"},\"nonselection_glyph\":{\"id\":\"2318\"},\"view\":{\"id\":\"2321\"}},\"id\":\"2320\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"source\":{\"id\":\"2316\"}},\"id\":\"2321\",\"type\":\"CDSView\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"2298\"},\"glyph\":{\"id\":\"2299\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"2301\"},\"nonselection_glyph\":{\"id\":\"2300\"},\"view\":{\"id\":\"2303\"}},\"id\":\"2302\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis_label\":\"sections\",\"coordinates\":null,\"formatter\":{\"id\":\"2291\"},\"group\":null,\"major_label_policy\":{\"id\":\"2292\"},\"ticker\":{\"id\":\"2263\"}},\"id\":\"2262\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"2357\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"2334\",\"type\":\"Selection\"},{\"attributes\":{\"source\":{\"id\":\"2298\"}},\"id\":\"2303\",\"type\":\"CDSView\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#FFB6C1\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2318\",\"type\":\"Line\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"red\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2339\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"2356\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"line_color\":\"#FFB6C1\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2317\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"2260\",\"type\":\"LogScale\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"2337\"},\"glyph\":{\"id\":\"2338\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"2340\"},\"nonselection_glyph\":{\"id\":\"2339\"},\"view\":{\"id\":\"2342\"}},\"id\":\"2341\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"2272\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"2382\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"2313\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"label\":{\"value\":\"y=x\"},\"renderers\":[{\"id\":\"2284\"},{\"id\":\"2302\"}]},\"id\":\"2297\",\"type\":\"LegendItem\"},{\"attributes\":{\"label\":{\"value\":\"y=10^x^2\"},\"renderers\":[{\"id\":\"2388\"}]},\"id\":\"2410\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"2333\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"2314\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"2381\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"2263\",\"type\":\"BasicTicker\"},{\"attributes\":{\"fill_color\":{\"value\":\"white\"},\"line_color\":{\"value\":\"red\"},\"size\":{\"value\":6},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2361\",\"type\":\"Circle\"},{\"attributes\":{\"ticker\":null},\"id\":\"2288\",\"type\":\"LogTickFormatter\"},{\"attributes\":{\"axis\":{\"id\":\"2262\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"2265\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"2289\",\"type\":\"AllLabels\"},{\"attributes\":{\"data\":{\"x\":[0.1,0.5,1.0,1.5,2.0,2.5,3.0],\"y\":[0.010000000000000002,0.25,1.0,2.25,4.0,6.25,9.0]},\"selected\":{\"id\":\"2334\"},\"selection_policy\":{\"id\":\"2333\"}},\"id\":\"2316\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"label\":{\"value\":\"y=x^2\"},\"renderers\":[{\"id\":\"2320\"}]},\"id\":\"2336\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"2291\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"2273\",\"type\":\"SaveTool\"},{\"attributes\":{\"source\":{\"id\":\"2384\"}},\"id\":\"2389\",\"type\":\"CDSView\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"2384\"},\"glyph\":{\"id\":\"2385\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"2387\"},\"nonselection_glyph\":{\"id\":\"2386\"},\"view\":{\"id\":\"2389\"}},\"id\":\"2388\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"click_policy\":\"hide\",\"coordinates\":null,\"group\":null,\"items\":[{\"id\":\"2297\"},{\"id\":\"2336\"},{\"id\":\"2359\"},{\"id\":\"2410\"}],\"location\":\"top_left\"},\"id\":\"2296\",\"type\":\"Legend\"},{\"attributes\":{\"tools\":[{\"id\":\"2270\"},{\"id\":\"2271\"},{\"id\":\"2272\"},{\"id\":\"2273\"}]},\"id\":\"2275\",\"type\":\"Toolbar\"},{\"attributes\":{\"line_color\":\"#1f77b4\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2281\",\"type\":\"Line\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2282\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"2256\",\"type\":\"DataRange1d\"},{\"attributes\":{\"fill_color\":{\"value\":\"white\"},\"line_color\":{\"value\":\"#1f77b4\"},\"size\":{\"value\":8},\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2299\",\"type\":\"Circle\"},{\"attributes\":{\"source\":{\"id\":\"2280\"}},\"id\":\"2285\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"2292\",\"type\":\"AllLabels\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"2274\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"line_alpha\":0.2,\"line_color\":\"orange\",\"line_dash\":[4,4],\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2387\",\"type\":\"Line\"},{\"attributes\":{\"line_alpha\":0.2,\"line_color\":\"#1f77b4\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2283\",\"type\":\"Line\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"orange\",\"line_dash\":[4,4],\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2386\",\"type\":\"Line\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"2280\"},\"glyph\":{\"id\":\"2281\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"2283\"},\"nonselection_glyph\":{\"id\":\"2282\"},\"view\":{\"id\":\"2285\"}},\"id\":\"2284\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"data\":{\"x\":[0.1,0.5,1.0,1.5,2.0,2.5,3.0],\"y\":[0.1,0.5,1.0,1.5,2.0,2.5,3.0]},\"selected\":{\"id\":\"2314\"},\"selection_policy\":{\"id\":\"2313\"}},\"id\":\"2298\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"line_alpha\":0.2,\"line_color\":\"red\",\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2340\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"2407\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"2254\",\"type\":\"DataRange1d\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"2360\"},\"glyph\":{\"id\":\"2361\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"2363\"},\"nonselection_glyph\":{\"id\":\"2362\"},\"view\":{\"id\":\"2365\"}},\"id\":\"2364\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"2270\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"2408\",\"type\":\"Selection\"},{\"attributes\":{\"line_color\":\"orange\",\"line_dash\":[4,4],\"x\":{\"field\":\"x\"},\"y\":{\"field\":\"y\"}},\"id\":\"2385\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"2293\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"2294\",\"type\":\"Selection\"},{\"attributes\":{\"axis_label\":\"particles\",\"coordinates\":null,\"formatter\":{\"id\":\"2288\"},\"group\":null,\"major_label_policy\":{\"id\":\"2289\"},\"ticker\":{\"id\":\"2267\"}},\"id\":\"2266\",\"type\":\"LogAxis\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"log axis example\"},\"id\":\"2252\",\"type\":\"Title\"},{\"attributes\":{\"data\":{\"x\":[0.1,0.5,1.0,1.5,2.0,2.5,3.0],\"y\":[0.1,0.5,1.0,1.5,2.0,2.5,3.0]},\"selected\":{\"id\":\"2294\"},\"selection_policy\":{\"id\":\"2293\"}},\"id\":\"2280\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"axis\":{\"id\":\"2266\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"2269\",\"type\":\"Grid\"},{\"attributes\":{\"data\":{\"x\":[0.1,0.5,1.0,1.5,2.0,2.5,3.0],\"y\":[1.023292992280754,1.7782794100389228,10.0,177.82794100389228,10000.0,1778279.410038923,1000000000.0]},\"selected\":{\"id\":\"2408\"},\"selection_policy\":{\"id\":\"2407\"}},\"id\":\"2384\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"source\":{\"id\":\"2337\"}},\"id\":\"2342\",\"type\":\"CDSView\"}],\"root_ids\":[\"2251\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.1\"}};\n",
       "  const render_items = [{\"docid\":\"9ce83511-c002-43a7-8bd5-e20a7a5a094e\",\"root_ids\":[\"2251\"],\"roots\":{\"2251\":\"fcc313e6-62fa-49a4-a33f-e579d490349d\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2251"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "x = [0.1,0.5,1.0,1.5,2.0,2.5,3.0]\n",
    "y0 = [i**2 for i in x]\n",
    "y1 = [10**i for i in x]\n",
    "y2 = [10**(i**2) for i in x]\n",
    "\n",
    "p = figure(\n",
    "    tools=\"pan,box_zoom,reset,save\",\n",
    "    y_axis_type=\"log\", title=\"log axis example\",\n",
    "    x_axis_label='sections', y_axis_label='particles',\n",
    "    width=300, height=300\n",
    ")\n",
    "\n",
    "p.line(x,x,legend=\"y=x\")\n",
    "p.circle(x,x,legend=\"y=x\",fill_color=\"white\",size=8)\n",
    "p.line(x,y0,legend=\"y=x^2\",line_color=\"#FFB6C1\")\n",
    "p.line(x, y1, legend=\"y=10^x\", line_color=\"red\")\n",
    "p.circle(x, y1, legend=\"y=10^x\", fill_color=\"white\", line_color=\"red\", size=6)\n",
    "p.line(x, y2, legend=\"y=10^x^2\", line_color=\"orange\", line_dash=\"4 4\")\n",
    "\n",
    "# 图例设置\n",
    "p.legend.location=\"top_left\"\n",
    "p.legend.click_policy = \"hide\"\n",
    "\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "13b25a9e",
   "metadata": {},
   "source": [
    "### 示例代码2： us_marriages_divorces"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "f1e8b7c2",
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.models import ColumnDataSource, NumeralTickFormatter, SingleIntervalTicker\n",
    "from bokeh.sampledata.us_marriages_divorces import data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "884d1f24",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Year</th>\n",
       "      <th>Marriages</th>\n",
       "      <th>Divorces</th>\n",
       "      <th>Population</th>\n",
       "      <th>Marriages_per_1000</th>\n",
       "      <th>Divorces_per_1000</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1867</td>\n",
       "      <td>357000.0</td>\n",
       "      <td>10000.0</td>\n",
       "      <td>36970000</td>\n",
       "      <td>9.7</td>\n",
       "      <td>0.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1868</td>\n",
       "      <td>345000.0</td>\n",
       "      <td>10000.0</td>\n",
       "      <td>37885000</td>\n",
       "      <td>9.1</td>\n",
       "      <td>0.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1869</td>\n",
       "      <td>348000.0</td>\n",
       "      <td>11000.0</td>\n",
       "      <td>38870000</td>\n",
       "      <td>9.0</td>\n",
       "      <td>0.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1870</td>\n",
       "      <td>352000.0</td>\n",
       "      <td>11000.0</td>\n",
       "      <td>39905000</td>\n",
       "      <td>8.8</td>\n",
       "      <td>0.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1871</td>\n",
       "      <td>359000.0</td>\n",
       "      <td>12000.0</td>\n",
       "      <td>41010000</td>\n",
       "      <td>8.8</td>\n",
       "      <td>0.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>140</th>\n",
       "      <td>2007</td>\n",
       "      <td>2197000.0</td>\n",
       "      <td>856000.0</td>\n",
       "      <td>301696000</td>\n",
       "      <td>7.3</td>\n",
       "      <td>2.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>141</th>\n",
       "      <td>2008</td>\n",
       "      <td>2157000.0</td>\n",
       "      <td>844000.0</td>\n",
       "      <td>304543000</td>\n",
       "      <td>7.1</td>\n",
       "      <td>2.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>142</th>\n",
       "      <td>2009</td>\n",
       "      <td>2080000.0</td>\n",
       "      <td>840000.0</td>\n",
       "      <td>307240000</td>\n",
       "      <td>6.8</td>\n",
       "      <td>2.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>143</th>\n",
       "      <td>2010</td>\n",
       "      <td>2096000.0</td>\n",
       "      <td>872000.0</td>\n",
       "      <td>309776000</td>\n",
       "      <td>6.8</td>\n",
       "      <td>2.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>144</th>\n",
       "      <td>2011</td>\n",
       "      <td>2118000.0</td>\n",
       "      <td>877000.0</td>\n",
       "      <td>312034000</td>\n",
       "      <td>6.8</td>\n",
       "      <td>2.8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>145 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     Year  Marriages  Divorces  Population  Marriages_per_1000  \\\n",
       "0    1867   357000.0   10000.0    36970000                 9.7   \n",
       "1    1868   345000.0   10000.0    37885000                 9.1   \n",
       "2    1869   348000.0   11000.0    38870000                 9.0   \n",
       "3    1870   352000.0   11000.0    39905000                 8.8   \n",
       "4    1871   359000.0   12000.0    41010000                 8.8   \n",
       "..    ...        ...       ...         ...                 ...   \n",
       "140  2007  2197000.0  856000.0   301696000                 7.3   \n",
       "141  2008  2157000.0  844000.0   304543000                 7.1   \n",
       "142  2009  2080000.0  840000.0   307240000                 6.8   \n",
       "143  2010  2096000.0  872000.0   309776000                 6.8   \n",
       "144  2011  2118000.0  877000.0   312034000                 6.8   \n",
       "\n",
       "     Divorces_per_1000  \n",
       "0                  0.3  \n",
       "1                  0.3  \n",
       "2                  0.3  \n",
       "3                  0.3  \n",
       "4                  0.3  \n",
       "..                 ...  \n",
       "140                2.8  \n",
       "141                2.8  \n",
       "142                2.7  \n",
       "143                2.8  \n",
       "144                2.8  \n",
       "\n",
       "[145 rows x 6 columns]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "6b3cd862",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = data.interpolate(method='linear', axis=0).ffill().bfill()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "ea043245",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1867, 1868, 1869, 1870, 1871, 1872, 1873, 1874, 1875, 1876, 1877,\n",
       "       1878, 1879, 1880, 1881, 1882, 1883, 1884, 1885, 1886, 1887, 1888,\n",
       "       1889, 1890, 1891, 1892, 1893, 1894, 1895, 1896, 1897, 1898, 1899,\n",
       "       1900, 1901, 1902, 1903, 1904, 1905, 1906, 1907, 1908, 1909, 1910,\n",
       "       1911, 1912, 1913, 1914, 1915, 1916, 1917, 1918, 1919, 1920, 1921,\n",
       "       1922, 1923, 1924, 1925, 1926, 1927, 1928, 1929, 1930, 1931, 1932,\n",
       "       1933, 1934, 1935, 1936, 1937, 1938, 1939, 1940, 1941, 1942, 1943,\n",
       "       1944, 1945, 1946, 1947, 1948, 1949, 1950, 1951, 1952, 1953, 1954,\n",
       "       1955, 1956, 1957, 1958, 1959, 1960, 1961, 1962, 1963, 1964, 1965,\n",
       "       1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976,\n",
       "       1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987,\n",
       "       1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,\n",
       "       1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,\n",
       "       2010, 2011], dtype=int64)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.Year.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "424ff547",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 357000.        ,  345000.        ,  348000.        ,\n",
       "        352000.        ,  359000.        ,  378000.        ,\n",
       "        386000.        ,  385000.        ,  409000.        ,\n",
       "        405000.        ,  411000.        ,  423000.        ,\n",
       "        438000.        ,  453000.        ,  464000.        ,\n",
       "        484000.        ,  501000.        ,  485000.        ,\n",
       "        507000.        ,  534000.        ,  513000.        ,\n",
       "        535000.        ,  563000.        ,  570000.        ,\n",
       "        592000.        ,  601000.        ,  601000.        ,\n",
       "        588000.        ,  620000.        ,  635000.        ,\n",
       "        643000.        ,  647000.        ,  673000.        ,\n",
       "        709000.        ,  742000.        ,  776000.        ,\n",
       "        818000.        ,  815000.        ,  842000.        ,\n",
       "        895000.        ,  937000.        ,  857000.        ,\n",
       "        897000.        ,  948000.        ,  955000.        ,\n",
       "       1005000.        , 1021000.        , 1025000.        ,\n",
       "       1008000.        , 1076000.        , 1144000.        ,\n",
       "       1000000.        , 1150000.        , 1274000.        ,\n",
       "       1164000.        , 1134000.        , 1230000.        ,\n",
       "       1185000.        , 1188000.        , 1203000.        ,\n",
       "       1201000.        , 1182000.        , 1233000.        ,\n",
       "       1127000.        , 1061000.        ,  982000.        ,\n",
       "       1098000.        , 1302000.        , 1327000.        ,\n",
       "       1369000.        , 1451000.        , 1331000.        ,\n",
       "       1404000.        , 1596000.        , 1696000.        ,\n",
       "       1772000.        , 1577000.        , 1452000.        ,\n",
       "       1613000.        , 2291000.        , 1992000.        ,\n",
       "       1811000.        , 1580000.        , 1667000.        ,\n",
       "       1595000.        , 1539000.        , 1546000.        ,\n",
       "       1490000.        , 1531000.        , 1585000.        ,\n",
       "       1518000.        , 1451000.        , 1494000.        ,\n",
       "       1523000.        , 1548000.        , 1577000.        ,\n",
       "       1654000.        , 1725000.        , 1800000.        ,\n",
       "       1857000.        , 1927000.        , 2069000.        ,\n",
       "       2145000.        , 2185802.        , 2190481.        ,\n",
       "       2282154.        , 2284108.        , 2245929.        ,\n",
       "       2159810.        , 2159051.        , 2180861.        ,\n",
       "       2293079.        , 2341102.        , 2413896.        ,\n",
       "       2438085.        , 2452769.        , 2467453.        ,\n",
       "       2482137.        , 2408911.        , 2406830.        ,\n",
       "       2404146.        , 2377092.        , 2399654.        ,\n",
       "       2451774.        , 2383182.        , 2389375.        ,\n",
       "       2342538.        , 2397441.        , 2392960.66666667,\n",
       "       2388480.33333333, 2384000.        , 2244000.        ,\n",
       "       2358000.        , 2315000.        , 2326000.        ,\n",
       "       2290000.        , 2245000.        , 2279000.        ,\n",
       "       2249000.        , 2193000.        , 2197000.        ,\n",
       "       2157000.        , 2080000.        , 2096000.        ,\n",
       "       2118000.        ])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.Marriages.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "896ab924",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  10000.        ,   10000.        ,   11000.        ,\n",
       "         11000.        ,   12000.        ,   12000.        ,\n",
       "         13000.        ,   14000.        ,   14000.        ,\n",
       "         15000.        ,   16000.        ,   16000.        ,\n",
       "         17000.        ,   20000.        ,   21000.        ,\n",
       "         22000.        ,   23000.        ,   23000.        ,\n",
       "         23000.        ,   26000.        ,   28000.        ,\n",
       "         29000.        ,   32000.        ,   33000.        ,\n",
       "         36000.        ,   37000.        ,   37000.        ,\n",
       "         38000.        ,   40000.        ,   43000.        ,\n",
       "         45000.        ,   48000.        ,   51000.        ,\n",
       "         56000.        ,   61000.        ,   61000.        ,\n",
       "         65000.        ,   66000.        ,   68000.        ,\n",
       "         72000.        ,   77000.        ,   77000.        ,\n",
       "         80000.        ,   83000.        ,   89000.        ,\n",
       "         94000.        ,   91000.        ,  101000.        ,\n",
       "        104000.        ,  114000.        ,  122000.        ,\n",
       "        116000.        ,  142000.        ,  171000.        ,\n",
       "        160000.        ,  149000.        ,  165000.        ,\n",
       "        171000.        ,  175000.        ,  185000.        ,\n",
       "        196000.        ,  200000.        ,  206000.        ,\n",
       "        196000.        ,  188000.        ,  164000.        ,\n",
       "        165000.        ,  204000.        ,  218000.        ,\n",
       "        236000.        ,  249000.        ,  244000.        ,\n",
       "        251000.        ,  264000.        ,  293000.        ,\n",
       "        321000.        ,  359000.        ,  400000.        ,\n",
       "        485000.        ,  610000.        ,  483000.        ,\n",
       "        408000.        ,  397000.        ,  385000.        ,\n",
       "        381000.        ,  392000.        ,  390000.        ,\n",
       "        379000.        ,  377000.        ,  382000.        ,\n",
       "        381000.        ,  368000.        ,  395000.        ,\n",
       "        393000.        ,  414000.        ,  413000.        ,\n",
       "        428000.        ,  450000.        ,  479000.        ,\n",
       "        499000.        ,  523000.        ,  584000.        ,\n",
       "        639000.        ,  708000.        ,  773000.        ,\n",
       "        845000.        ,  915000.        ,  983931.        ,\n",
       "       1036709.        , 1090430.        , 1101445.        ,\n",
       "       1135408.        , 1193062.        , 1184175.        ,\n",
       "       1219042.        , 1206684.66666667, 1194327.33333333,\n",
       "       1181970.        , 1192530.        , 1179347.        ,\n",
       "       1165646.        , 1151787.        , 1162719.        ,\n",
       "       1175851.        , 1191591.        , 1233226.        ,\n",
       "       1197297.        , 1211893.        , 1195595.33333333,\n",
       "       1179297.66666667, 1163000.        , 1135000.        ,\n",
       "       1145245.        ,  944000.        ,  940000.        ,\n",
       "        955000.        ,  927000.        ,  879000.        ,\n",
       "        847000.        ,  872000.        ,  856000.        ,\n",
       "        844000.        ,  840000.        ,  872000.        ,\n",
       "        877000.        ])"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.Divorces.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "fab88c4d",
   "metadata": {},
   "outputs": [],
   "source": [
    "source = ColumnDataSource(data = dict(\n",
    "    year = data.Year.values,\n",
    "    marriages = data.Marriages.values,\n",
    "    divorces = data.Divorces.values\n",
    "))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "e5e9f3a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"display: table;\"><div style=\"display: table-row;\"><div style=\"display: table-cell;\"><b title=\"bokeh.models.sources.ColumnDataSource\">ColumnDataSource</b>(</div><div style=\"display: table-cell;\">id&nbsp;=&nbsp;'2611', <span id=\"2613\" style=\"cursor: pointer;\">&hellip;)</span></div></div><div class=\"2612\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">data&nbsp;=&nbsp;{'marriages': {'__ndarray__': 'AAAAACDKFUEAAAAAoA4VQQAAAACAPRVBAAAAAAB8FUEAAAAAYOkVQQAAAABAEhdBAAAAAECPF0EAAAAAoH8XQQAAAACg9hhBAAAAACC4GEEAAAAA4BUZQQAAAABg0RlBAAAAAMC7GkEAAAAAIKYbQQAAAAAAUhxBAAAAAICKHUEAAAAAIJQeQQAAAAAgmh1BAAAAAODxHkEAAAAA4EsgQQAAAACgTx9BAAAAALBTIEEAAAAAcC4hQQAAAAAgZSFBAAAAAAARIkEAAAAAUFciQQAAAABQVyJBAAAAAMDxIUEAAAAAwOsiQQAAAADwYCNBAAAAAHCfI0EAAAAAsL4jQQAAAADQiSRBAAAAABCjJUEAAAAA4KQmQQAAAACAridBAAAAAKD2KEEAAAAAMN8oQQAAAAAgsilBAAAAADBQK0EAAAAAUJgsQQAAAABQJypBAAAAANBfK0EAAAAAQO4sQQAAAADwJC1BAAAAAJCrLkEAAAAAkCgvQQAAAADQRy9BAAAAAADDLkEAAAAAIGswQQAAAADAdDFBAAAAAICELkEAAAAAMIwxQQAAAACQcDNBAAAAAODCMUEAAAAAsE0xQQAAAACwxDJBAAAAAOgUMkEAAAAAoCAyQQAAAAA4WzJBAAAAAGhTMkEAAAAAMAkyQQAAAABo0DJBAAAAAFgyMUEAAAAAiDAwQQAAAADg9y1BAAAAABDBMEEAAAAA8N0zQQAAAACYPzRBAAAAAKjjNEEAAAAA+CM2QQAAAAA4TzRBAAAAAGBsNUEAAAAAYFo4QQAAAAAA4TlBAAAAAOAJO0EAAAAAKBA4QQAAAADgJzZBAAAAAMicOEEAAAAAnHpBQQAAAABAZT5BAAAAADiiO0EAAAAA4Bs4QQAAAAC4bzlBAAAAAHhWOEEAAAAAuHs3QQAAAAAQlzdBAAAAAFC8NkEAAAAAeFw3QQAAAABoLzhBAAAAALApN0EAAAAA+CM2QQAAAADwyzZBAAAAADg9N0EAAAAA4J43QQAAAAAoEDhBAAAAAPA8OUEAAAAASFI6QQAAAABAdztBAAAAAOhVPEEAAAAAWGc9QQAAAAAIkj9BAAAAAHRdQEEAAAAAJa1AQQAAAIBItkBBAAAAAFVpQUEAAAAAJm1BQQAAAICUIkFBAAAAAGF6QEEAAACA5XhAQQAAAIB+o0BBAAAAgKt+QUEAAAAAd9xBQQAAAACkakJBAAAAgOKZQkEAAACAkLZCQQAAAIA+00JBAAAAgOzvQkEAAACA52BCQQAAAADXXEJBAAAAAJlXQkEAAAAAwiJCQQAAAADTTkJBAAAAAJ+0QkEAAAAApy5CQQAAAIC/OkJBAAAAAEXfQUEAAACAgEpCQVVVVVXAQUJBq6qqKgA5QkEAAAAAQDBCQQAAAADQHkFBAAAAAHj9QUEAAAAAfKlBQQAAAAD4vkFBAAAAAKh4QUEAAAAAxCBBQQAAAAAsY0FBAAAAAJQoQUEAAAAANLtAQQAAAAAEw0BBAAAAAOR0QEEAAAAAAL0/QQAAAACA+z9BAAAAALgoQEE=', 'shape': (145,), 'dtype': 'float64', 'order': 'little'}, 'year': [1867, 1868, 1869, 1870, 1871, 1872, 1873, 1874, 1875, 1876, 1877, 1878, 1879, 1880, 1881, 1882, 1883, 1884, 1885, 1886, 1887, 1888, 1889, 1890, 1891, 1892, 1893, 1894, 1895, 1896, 1897, 1898, 1899, 1900, 1901, 1902, 1903, 1904, 1905, 1906, 1907, 1908, 1909, 1910, 1911, 1912, 1913, 1914, 1915, 1916, 1917, 1918, 1919, 1920, 1921, 1922, 1923, 1924, 1925, 1926, 1927, 1928, 1929, 1930, 1931, 1932, 1933, 1934, 1935, 1936, 1937, 1938, 1939, 1940, 1941, 1942, 1943, 1944, 1945, 1946, 1947, 1948, 1949, 1950, 1951, 1952, 1953, 1954, 1955, 1956, 1957, 1958, 1959, 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011], 'divorces': {'__ndarray__': 'AAAAAACIw0AAAAAAAIjDQAAAAAAAfMVAAAAAAAB8xUAAAAAAAHDHQAAAAAAAcMdAAAAAAABkyUAAAAAAAFjLQAAAAAAAWMtAAAAAAABMzUAAAAAAAEDPQAAAAAAAQM9AAAAAAACa0EAAAAAAAIjTQAAAAAAAgtRAAAAAAAB81UAAAAAAAHbWQAAAAAAAdtZAAAAAAAB21kAAAAAAAGTZQAAAAAAAWNtAAAAAAABS3EAAAAAAAEDfQAAAAAAAHeBAAAAAAACU4UAAAAAAABHiQAAAAAAAEeJAAAAAAACO4kAAAAAAAIjjQAAAAAAA/+RAAAAAAAD55UAAAAAAAHDnQAAAAAAA5+hAAAAAAABY60AAAAAAAMntQAAAAAAAye1AAAAAAAC970AAAAAAAB3wQAAAAAAAmvBAAAAAAACU8UAAAAAAgMzyQAAAAACAzPJAAAAAAACI80AAAAAAgEP0QAAAAACAuvVAAAAAAADz9kAAAAAAgDf2QAAAAACAqPhAAAAAAABk+UAAAAAAANX7QAAAAAAAyf1AAAAAAABS/EAAAAAAgFUBQQAAAADA3wRBAAAAAACIA0EAAAAAQDACQQAAAABAJARBAAAAAMDfBEEAAAAAwFwFQQAAAABAlQZBAAAAAADtB0EAAAAAAGoIQQAAAACAJQlBAAAAAADtB0EAAAAAAPMGQQAAAAAABQRBAAAAAEAkBEEAAAAAAOcIQQAAAACAnApBAAAAAADPDEEAAAAAQGUOQQAAAAAAyQ1BAAAAAMCjDkEAAAAAAB0QQQAAAAAg4hFBAAAAAKCXE0EAAAAAYOkVQQAAAAAAahhBAAAAACCaHUEAAAAAoJ0iQQAAAADgeh1BAAAAAADnGEEAAAAAIDsYQQAAAACgfxdBAAAAACBBF0EAAAAAAO0XQQAAAADAzRdBAAAAAOAhF0EAAAAAoAIXQQAAAADAUBdBAAAAACBBF0EAAAAAAHYWQQAAAADgGxhBAAAAAKD8F0EAAAAAwEQZQQAAAAAgNRlBAAAAAIAfGkEAAAAAQHcbQQAAAABgPB1BAAAAAOB0HkEAAAAA4OsfQQAAAACA0iFBAAAAADCAI0EAAAAAQJslQQAAAAAQlydBAAAAAJDJKUEAAAAAcOwrQQAAAAD2Bi5BAAAAAEqjL0EAAAAAfqMwQQAAAACFzjBBAAAAADBTMUEAAAAAZjQyQQAAAACvETJBAAAAAOKZMkGrqqqqnGkyQVVVVVVXOTJBAAAAABIJMkEAAAAAUjIyQQAAAADT/jFBAAAAAE7JMUEAAAAAK5MxQQAAAADfvTFBAAAAACvxMUEAAAAApy4yQQAAAABK0TJBAAAAAPFEMkEAAAAA9X0yQVVVVVVLPjJBq6qqqqH+MUEAAAAA+L4xQQAAAACYUTFBAAAAAJ15MUEAAAAAAM8sQQAAAADAryxBAAAAAPAkLUEAAAAAMEosQQAAAAAw0ypBAAAAADDZKUEAAAAAgJwqQQAAAACAHypBAAAAAMDBKUEAAAAAgKIpQQAAAACAnCpBAAAAAJDDKkE=', 'shape': (145,), 'dtype': 'float64', 'order': 'little'}},</div></div><div class=\"2612\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">js_event_callbacks&nbsp;=&nbsp;{},</div></div><div class=\"2612\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">js_property_callbacks&nbsp;=&nbsp;{},</div></div><div class=\"2612\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">name&nbsp;=&nbsp;None,</div></div><div class=\"2612\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">selected&nbsp;=&nbsp;Selection(id='2615', ...),</div></div><div class=\"2612\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">selection_policy&nbsp;=&nbsp;UnionRenderers(id='2614', ...),</div></div><div class=\"2612\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">subscribed_events&nbsp;=&nbsp;[],</div></div><div class=\"2612\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">syncable&nbsp;=&nbsp;True,</div></div><div class=\"2612\" style=\"display: none;\"><div style=\"display: table-cell;\"></div><div style=\"display: table-cell;\">tags&nbsp;=&nbsp;[])</div></div></div>\n",
       "<script>\n",
       "(function() {\n",
       "  let expanded = false;\n",
       "  const ellipsis = document.getElementById(\"2613\");\n",
       "  ellipsis.addEventListener(\"click\", function() {\n",
       "    const rows = document.getElementsByClassName(\"2612\");\n",
       "    for (let i = 0; i < rows.length; i++) {\n",
       "      const el = rows[i];\n",
       "      el.style.display = expanded ? \"none\" : \"table-row\";\n",
       "    }\n",
       "    ellipsis.innerHTML = expanded ? \"&hellip;)\" : \"&lsaquo;&lsaquo;&lsaquo;\";\n",
       "    expanded = !expanded;\n",
       "  });\n",
       "})();\n",
       "</script>\n"
      ],
      "text/plain": [
       "ColumnDataSource(id='2611', ...)"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "source"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "19d30bc3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"3a412715-b362-4830-bdc1-d2afd3d3726d\" data-root-id=\"2819\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  const docs_json = {\"e328ef76-b63d-4da3-92e1-e3159f5f8b7c\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2828\"}],\"center\":[{\"id\":\"2831\"},{\"id\":\"2835\"}],\"height\":500,\"left\":[{\"id\":\"2832\"}],\"renderers\":[{\"id\":\"2860\"},{\"id\":\"2866\"}],\"title\":{\"id\":\"2855\"},\"toolbar\":{\"id\":\"2843\"},\"width\":800,\"x_range\":{\"id\":\"2820\"},\"x_scale\":{\"id\":\"2824\"},\"y_range\":{\"id\":\"2822\"},\"y_scale\":{\"id\":\"2826\"}},\"id\":\"2819\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"2820\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"2981\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#1f77b4\",\"line_width\":3,\"x\":{\"field\":\"year\"},\"y\":{\"field\":\"marriages\"}},\"id\":\"2858\",\"type\":\"Line\"},{\"attributes\":{\"line_alpha\":0.1,\"line_color\":\"#ff7f0e\",\"line_width\":3,\"x\":{\"field\":\"year\"},\"y\":{\"field\":\"divorces\"}},\"id\":\"2864\",\"type\":\"Line\"},{\"attributes\":{\"line_alpha\":0.2,\"line_color\":\"#ff7f0e\",\"line_width\":3,\"x\":{\"field\":\"year\"},\"y\":{\"field\":\"divorces\"}},\"id\":\"2865\",\"type\":\"Line\"},{\"attributes\":{},\"id\":\"2614\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"2840\",\"type\":\"SaveTool\"},{\"attributes\":{\"interval\":10,\"num_minor_ticks\":0},\"id\":\"2851\",\"type\":\"SingleIntervalTicker\"},{\"attributes\":{},\"id\":\"2982\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"2980\",\"type\":\"AllLabels\"},{\"attributes\":{\"axis\":{\"id\":\"2828\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"2831\",\"type\":\"Grid\"},{\"attributes\":{\"line_alpha\":0.2,\"line_color\":\"#1f77b4\",\"line_width\":3,\"x\":{\"field\":\"year\"},\"y\":{\"field\":\"marriages\"}},\"id\":\"2859\",\"type\":\"Line\"},{\"attributes\":{\"source\":{\"id\":\"2611\"}},\"id\":\"2867\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"2615\",\"type\":\"Selection\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"2611\"},\"glyph\":{\"id\":\"2863\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"2865\"},\"name\":\"divorces\",\"nonselection_glyph\":{\"id\":\"2864\"},\"view\":{\"id\":\"2867\"}},\"id\":\"2866\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"data\":{\"divorces\":{\"__ndarray__\":\"AAAAAACIw0AAAAAAAIjDQAAAAAAAfMVAAAAAAAB8xUAAAAAAAHDHQAAAAAAAcMdAAAAAAABkyUAAAAAAAFjLQAAAAAAAWMtAAAAAAABMzUAAAAAAAEDPQAAAAAAAQM9AAAAAAACa0EAAAAAAAIjTQAAAAAAAgtRAAAAAAAB81UAAAAAAAHbWQAAAAAAAdtZAAAAAAAB21kAAAAAAAGTZQAAAAAAAWNtAAAAAAABS3EAAAAAAAEDfQAAAAAAAHeBAAAAAAACU4UAAAAAAABHiQAAAAAAAEeJAAAAAAACO4kAAAAAAAIjjQAAAAAAA/+RAAAAAAAD55UAAAAAAAHDnQAAAAAAA5+hAAAAAAABY60AAAAAAAMntQAAAAAAAye1AAAAAAAC970AAAAAAAB3wQAAAAAAAmvBAAAAAAACU8UAAAAAAgMzyQAAAAACAzPJAAAAAAACI80AAAAAAgEP0QAAAAACAuvVAAAAAAADz9kAAAAAAgDf2QAAAAACAqPhAAAAAAABk+UAAAAAAANX7QAAAAAAAyf1AAAAAAABS/EAAAAAAgFUBQQAAAADA3wRBAAAAAACIA0EAAAAAQDACQQAAAABAJARBAAAAAMDfBEEAAAAAwFwFQQAAAABAlQZBAAAAAADtB0EAAAAAAGoIQQAAAACAJQlBAAAAAADtB0EAAAAAAPMGQQAAAAAABQRBAAAAAEAkBEEAAAAAAOcIQQAAAACAnApBAAAAAADPDEEAAAAAQGUOQQAAAAAAyQ1BAAAAAMCjDkEAAAAAAB0QQQAAAAAg4hFBAAAAAKCXE0EAAAAAYOkVQQAAAAAAahhBAAAAACCaHUEAAAAAoJ0iQQAAAADgeh1BAAAAAADnGEEAAAAAIDsYQQAAAACgfxdBAAAAACBBF0EAAAAAAO0XQQAAAADAzRdBAAAAAOAhF0EAAAAAoAIXQQAAAADAUBdBAAAAACBBF0EAAAAAAHYWQQAAAADgGxhBAAAAAKD8F0EAAAAAwEQZQQAAAAAgNRlBAAAAAIAfGkEAAAAAQHcbQQAAAABgPB1BAAAAAOB0HkEAAAAA4OsfQQAAAACA0iFBAAAAADCAI0EAAAAAQJslQQAAAAAQlydBAAAAAJDJKUEAAAAAcOwrQQAAAAD2Bi5BAAAAAEqjL0EAAAAAfqMwQQAAAACFzjBBAAAAADBTMUEAAAAAZjQyQQAAAACvETJBAAAAAOKZMkGrqqqqnGkyQVVVVVVXOTJBAAAAABIJMkEAAAAAUjIyQQAAAADT/jFBAAAAAE7JMUEAAAAAK5MxQQAAAADfvTFBAAAAACvxMUEAAAAApy4yQQAAAABK0TJBAAAAAPFEMkEAAAAA9X0yQVVVVVVLPjJBq6qqqqH+MUEAAAAA+L4xQQAAAACYUTFBAAAAAJ15MUEAAAAAAM8sQQAAAADAryxBAAAAAPAkLUEAAAAAMEosQQAAAAAw0ypBAAAAADDZKUEAAAAAgJwqQQAAAACAHypBAAAAAMDBKUEAAAAAgKIpQQAAAACAnCpBAAAAAJDDKkE=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[145]},\"marriages\":{\"__ndarray__\":\"AAAAACDKFUEAAAAAoA4VQQAAAACAPRVBAAAAAAB8FUEAAAAAYOkVQQAAAABAEhdBAAAAAECPF0EAAAAAoH8XQQAAAACg9hhBAAAAACC4GEEAAAAA4BUZQQAAAABg0RlBAAAAAMC7GkEAAAAAIKYbQQAAAAAAUhxBAAAAAICKHUEAAAAAIJQeQQAAAAAgmh1BAAAAAODxHkEAAAAA4EsgQQAAAACgTx9BAAAAALBTIEEAAAAAcC4hQQAAAAAgZSFBAAAAAAARIkEAAAAAUFciQQAAAABQVyJBAAAAAMDxIUEAAAAAwOsiQQAAAADwYCNBAAAAAHCfI0EAAAAAsL4jQQAAAADQiSRBAAAAABCjJUEAAAAA4KQmQQAAAACAridBAAAAAKD2KEEAAAAAMN8oQQAAAAAgsilBAAAAADBQK0EAAAAAUJgsQQAAAABQJypBAAAAANBfK0EAAAAAQO4sQQAAAADwJC1BAAAAAJCrLkEAAAAAkCgvQQAAAADQRy9BAAAAAADDLkEAAAAAIGswQQAAAADAdDFBAAAAAICELkEAAAAAMIwxQQAAAACQcDNBAAAAAODCMUEAAAAAsE0xQQAAAACwxDJBAAAAAOgUMkEAAAAAoCAyQQAAAAA4WzJBAAAAAGhTMkEAAAAAMAkyQQAAAABo0DJBAAAAAFgyMUEAAAAAiDAwQQAAAADg9y1BAAAAABDBMEEAAAAA8N0zQQAAAACYPzRBAAAAAKjjNEEAAAAA+CM2QQAAAAA4TzRBAAAAAGBsNUEAAAAAYFo4QQAAAAAA4TlBAAAAAOAJO0EAAAAAKBA4QQAAAADgJzZBAAAAAMicOEEAAAAAnHpBQQAAAABAZT5BAAAAADiiO0EAAAAA4Bs4QQAAAAC4bzlBAAAAAHhWOEEAAAAAuHs3QQAAAAAQlzdBAAAAAFC8NkEAAAAAeFw3QQAAAABoLzhBAAAAALApN0EAAAAA+CM2QQAAAADwyzZBAAAAADg9N0EAAAAA4J43QQAAAAAoEDhBAAAAAPA8OUEAAAAASFI6QQAAAABAdztBAAAAAOhVPEEAAAAAWGc9QQAAAAAIkj9BAAAAAHRdQEEAAAAAJa1AQQAAAIBItkBBAAAAAFVpQUEAAAAAJm1BQQAAAICUIkFBAAAAAGF6QEEAAACA5XhAQQAAAIB+o0BBAAAAgKt+QUEAAAAAd9xBQQAAAACkakJBAAAAgOKZQkEAAACAkLZCQQAAAIA+00JBAAAAgOzvQkEAAACA52BCQQAAAADXXEJBAAAAAJlXQkEAAAAAwiJCQQAAAADTTkJBAAAAAJ+0QkEAAAAApy5CQQAAAIC/OkJBAAAAAEXfQUEAAACAgEpCQVVVVVXAQUJBq6qqKgA5QkEAAAAAQDBCQQAAAADQHkFBAAAAAHj9QUEAAAAAfKlBQQAAAAD4vkFBAAAAAKh4QUEAAAAAxCBBQQAAAAAsY0FBAAAAAJQoQUEAAAAANLtAQQAAAAAEw0BBAAAAAOR0QEEAAAAAAL0/QQAAAACA+z9BAAAAALgoQEE=\",\"dtype\":\"float64\",\"order\":\"little\",\"shape\":[145]},\"year\":[1867,1868,1869,1870,1871,1872,1873,1874,1875,1876,1877,1878,1879,1880,1881,1882,1883,1884,1885,1886,1887,1888,1889,1890,1891,1892,1893,1894,1895,1896,1897,1898,1899,1900,1901,1902,1903,1904,1905,1906,1907,1908,1909,1910,1911,1912,1913,1914,1915,1916,1917,1918,1919,1920,1921,1922,1923,1924,1925,1926,1927,1928,1929,1930,1931,1932,1933,1934,1935,1936,1937,1938,1939,1940,1941,1942,1943,1944,1945,1946,1947,1948,1949,1950,1951,1952,1953,1954,1955,1956,1957,1958,1959,1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011]},\"selected\":{\"id\":\"2615\"},\"selection_policy\":{\"id\":\"2614\"}},\"id\":\"2611\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"line_color\":\"#1f77b4\",\"line_width\":3,\"x\":{\"field\":\"year\"},\"y\":{\"field\":\"marriages\"}},\"id\":\"2857\",\"type\":\"Line\"},{\"attributes\":{\"tools\":[{\"id\":\"2836\"},{\"id\":\"2837\"},{\"id\":\"2838\"},{\"id\":\"2839\"},{\"id\":\"2840\"},{\"id\":\"2842\"}]},\"id\":\"2843\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"2839\",\"type\":\"ResetTool\"},{\"attributes\":{\"overlay\":{\"id\":\"2841\"}},\"id\":\"2838\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"2836\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"2837\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"2824\",\"type\":\"LinearScale\"},{\"attributes\":{\"axis_label\":\"# per 1,000 people\",\"coordinates\":null,\"formatter\":{\"id\":\"2853\"},\"group\":null,\"major_label_policy\":{\"id\":\"2980\"},\"ticker\":{\"id\":\"2833\"}},\"id\":\"2832\",\"type\":\"LinearAxis\"},{\"attributes\":{\"source\":{\"id\":\"2611\"}},\"id\":\"2861\",\"type\":\"CDSView\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"2981\"},\"group\":null,\"major_label_policy\":{\"id\":\"2982\"},\"ticker\":{\"id\":\"2851\"}},\"id\":\"2828\",\"type\":\"LinearAxis\"},{\"attributes\":{\"format\":\"0.0a\"},\"id\":\"2853\",\"type\":\"NumeralTickFormatter\"},{\"attributes\":{},\"id\":\"2826\",\"type\":\"LinearScale\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"2611\"},\"glyph\":{\"id\":\"2857\"},\"group\":null,\"hover_glyph\":null,\"muted_glyph\":{\"id\":\"2859\"},\"name\":\"marriages\",\"nonselection_glyph\":{\"id\":\"2858\"},\"view\":{\"id\":\"2861\"}},\"id\":\"2860\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"callback\":null,\"mode\":\"vline\",\"tooltips\":\"<font face=\\\"Arial\\\" size=\\\"3\\\">@$name{0.0} $name per 1,000 people in @year</font>\"},\"id\":\"2842\",\"type\":\"HoverTool\"},{\"attributes\":{},\"id\":\"2833\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"2822\",\"type\":\"DataRange1d\"},{\"attributes\":{\"axis\":{\"id\":\"2832\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"2835\",\"type\":\"Grid\"},{\"attributes\":{\"line_color\":\"#ff7f0e\",\"line_width\":3,\"x\":{\"field\":\"year\"},\"y\":{\"field\":\"divorces\"}},\"id\":\"2863\",\"type\":\"Line\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"144 years of marriage and divorce in the U.S.\"},\"id\":\"2855\",\"type\":\"Title\"},{\"attributes\":{\"bottom_units\":\"screen\",\"coordinates\":null,\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"group\":null,\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"syncable\":false,\"top_units\":\"screen\"},\"id\":\"2841\",\"type\":\"BoxAnnotation\"}],\"root_ids\":[\"2819\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.1\"}};\n",
       "  const render_items = [{\"docid\":\"e328ef76-b63d-4da3-92e1-e3159f5f8b7c\",\"root_ids\":[\"2819\"],\"roots\":{\"2819\":\"3a412715-b362-4830-bdc1-d2afd3d3726d\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    let attempts = 0;\n",
       "    const timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2819"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 设置工具条\n",
    "TOOLS = 'pan,wheel_zoom,box_zoom,reset,save'\n",
    "\n",
    "# 画布\n",
    "p = figure(tools=TOOLS, plot_width=800, plot_height=500,\n",
    "           tooltips='<font face=\"Arial\" size=\"3\">@$name{0.0} $name per 1,000 people in @year</font>')\n",
    "\n",
    "# 定义画布的内容（坐标轴刻度）models\n",
    "p.hover.mode = 'vline'\n",
    "p.xaxis.ticker = SingleIntervalTicker(interval=10, num_minor_ticks=0)\n",
    "p.yaxis.formatter = NumeralTickFormatter(format='0.0a')\n",
    "p.yaxis.axis_label = '# per 1,000 people'\n",
    "p.title.text = '144 years of marriage and divorce in the U.S.'\n",
    "\n",
    "# 绘图\n",
    "p.line('year', 'marriages', color='#1f77b4', line_width=3, source=source, name=\"marriages\")\n",
    "p.line('year', 'divorces', color='#ff7f0e', line_width=3, source=source, name=\"divorces\")\n",
    "\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cfece32c",
   "metadata": {},
   "source": [
    "### 实践:AAPL close收盘价折线图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "7aca821a",
   "metadata": {},
   "outputs": [],
   "source": [
    "from bokeh.sampledata.stocks import AAPL,GOOG\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "5cc0970d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 31.68,  29.66,  31.12, ..., 438.75, 435.62, 424.83])"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "aapl = np.array(AAPL['adj_close'])\n",
    "aapl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "bc1abb71",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['2000-03-01', '2000-03-02', '2000-03-03', ..., '2013-02-27',\n",
       "       '2013-02-28', '2013-03-01'], dtype='datetime64[D]')"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "appl_dates = np.array(AAPL['date'], dtype=np.datetime64)\n",
    "appl_dates"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "12c62d5c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([100.34, 108.31, 109.4 , ..., 799.78, 801.2 , 806.19])"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "goog = np.array(GOOG['adj_close'])\n",
    "goog"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "ddf7c037",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['2004-08-19', '2004-08-20', '2004-08-23', ..., '2013-02-27',\n",
       "       '2013-02-28', '2013-03-01'], dtype='datetime64[D]')"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "appl_dates = np.array(GOOG['date'], dtype=np.datetime64)\n",
    "appl_dates"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "42217d1e",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 准备数据：source = ColumnDataSource(data = dict())\n",
    "# 参考如下：\n",
    "source = ColumnDataSource(data = dict(\n",
    "    year = data.Year.values,\n",
    "    marriages = data.Marriages.values,\n",
    "    divorces = data.Divorces.values\n",
    "))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac78f9c1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "288px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
